package website.seamonster.ethegg.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import website.seamonster.ethegg.dto.ChickenDTO;
import website.seamonster.ethegg.dto.ChickenFramDTO;
import website.seamonster.ethegg.service.ChickenFarmService;
import website.seamonster.ethegg.service.UserService;
import website.seamonster.ethegg.utils.ResultVOUtil;
import website.seamonster.ethegg.viewobject.ResultVO;

import java.util.List;

/**
 * Created by 罗海量
 * 2018-07-23 00:12
 */
@lombok.extern.slf4j.Slf4j
@RestController
@RequestMapping("/farm")
public class ChickenFarmController {

    @Autowired
    private ChickenFarmService chickenFarmService;
    @Autowired
    private UserService userService;

    //鸡、蛋列表，鸡圈、空闲鸡圈
    @RequestMapping
    public ResultVO<ChickenFramDTO> getFarm(@RequestParam("userId") String userId){
        List<ChickenDTO> chickenFarmList = chickenFarmService.getChickenFarmList(userId);
        Integer maxHatchNum = userService.getMaxHatchNum(userId);
        Integer freeHatchNum = userService.getFreeHatchNum(userId);
        ChickenFramDTO chickenFramDTO = new ChickenFramDTO();
        chickenFramDTO.setChickens(chickenFarmList);
        chickenFramDTO.setMaxHatch(maxHatchNum);
        chickenFramDTO.setFreeFarmCnt(freeHatchNum);
        return ResultVOUtil.success(chickenFramDTO);
    }

}
